$(document).ready(function()
{	
	var rule_data = 0;
	$.getJSON("/score/resource/js/test.json",function(data)
	{
		rule_data= data;
	});
	var display = 0;
	$.getJSON("/score/resource/js/display.json",function(data)
	{
		display= data;
	});
	//$(".file").on("change",function(){
	//为新增加的input添加事件方法
	$(".repeat").on("change","input",function(){
		//files为读取的文件列表
		var url =window.webkitURL.createObjectURL(this.files[0]);
		//不能写成 img= $("img");
		var img = $("<img/>");

		//alert(url);
		//var files = document.getElementById("file").value;
		//var objUrl=getObjectURL(this.files[0]);
		// files.select();
		// var imgSrc = document.selection.createRange().text;
		// alert(imgSrc);
		//alert(files);
		 //$(".imgPreview").attr("src","http://localhost/score/upload/Desert.jpg");
		 //img.attr("class","preview_pic");
		 // img.css("width","80px");
		 // img.css("height","80px");
		 // img.attr("src",url);
		 var img = $(this).parent().parent().prev().find("img").attr("src",url).css("height","80px");
		 // img.attr("src",url);
		 // img.css("height","80px");
		 // img.css("height","80px");
		 // var input = $("<input/>");
		 // var name = parseInt($(this).attr("name"))+1;
		 // input.attr("type","file");
		 // input.attr("class","file");
		 // input.attr("name",name);
		 // input.css("width","80px");
		 // input.css("height","80px");
		 // input.css("background","red");
		 // $(".upload_pic").append(input);
		 // var upload_img = $("<img/>");
		 // upload_img.css("width","80px");
		 // upload_img.css("height","80px");
		 // $(".upload_button").prepend(upload_img);

	});

	$(".add_item").click(function(){
		var content = $(this).prev().find(".repeat_content").html();
		var new_item = $("<div></div>");
		new_item.attr("class","repeat_content");
		new_item.html(content);
		new_item.find(".imgPreview").html("<img>");
		new_item.find(".select_prize:gt(0)").html("");
		$(this).prev().append(new_item);
		//$(this).prev().append(content);
		//alert(content);
	});

	$(".repeat").on("change",".select_prize",function(){

		//alert(rule_data[0].id);
		var a = $(this).attr("name");
		a = a.split("_")[1];
		var rule_id = parseInt(a)-1;
		var parm = $(this).val();
		var relation_array = rule_data[rule_id].parm_relation[parm];
		var next_select = $(this).parent().next().find(".select_prize");
		next_select.html("");
		next_select.removeAttr("disabled"); 
		if(relation_array ==undefined)
			return;
		for(var i= 0; i< relation_array.length;i++){
			//alert(relation_array[i]);
			var option = $("<option></option>");
			option.attr("value",relation_array[i]);
			option.text(display[relation_array[i]]);
			next_select.append(option);
			//$(this).parent().next().find(".select_prize").html("");
		}

	});
});

function check()
{
	var check= 1;
    
	$(".select_prize").each(function(index)
	{
		if($(this).val() =="to_choose")
		{
			
			var a= $(this).parent().parent().parent().prev().html();
			var b= $(this).parent().parent().parent().prev().prev().html();
			alert("\""+b+a+"\""+"尚未填写");
			//$(this).css("color","red");
			location.href = "#anchor_"+b; 
			check= 0;
			return false;
		}
		
	});
	if(check == 1)
		return true;
	else
		return false;
}
